package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 巡查文件处理状态枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum PatrolFileProcessingStatus implements BaseEnum {
    PENDING("PENDING", "待处理"),
    IN_PROGRESS("IN_PROGRESS", "处理中"),
    COMPLETED("COMPLETED", "处理完成"),
    FAILED("FAILED", "处理失败"),
    CANCELLED("CANCELLED", "已取消"),
    SKIPPED("SKIPPED", "跳过处理");

    private final String code;
    private final String description;

    PatrolFileProcessingStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static PatrolFileProcessingStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Patrol file processing status code cannot be null or empty");
        }

        for (PatrolFileProcessingStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown patrol file processing status code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 枚举值，如果未找到返回null
     */
    public static PatrolFileProcessingStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (PatrolFileProcessingStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}